home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / pdf / c++ / DocViewChoices < prev    next >
Text File  |  2003-02-14  |  5KB  |  131 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #include "DocViewChoices.h"
  39. #include "uCompare.h"
  40. #include "fstream.h"
  41. #include "ChoicesFilePath.h"
  42. #include <stdlib.h>
  43.  
  44.  
  45. class DefaultChoices
  46. {
  47.   public:
  48.     int flags;
  49.     int scale;
  50.     int rotation;
  51.  
  52.     friend DefaultChoices& defaultChoices();
  53.  
  54.   private:
  55.     DefaultChoices();
  56. };
  57.  
  58. DefaultChoices::DefaultChoices()
  59.  : flags(DocViewChoices::HIGHLIGHT_LINKS),
  60.    scale(100),
  61.    rotation(0)
  62. {
  63.   string file=getChoicesFilePath("Setup");
  64.   char buf[128];
  65.   ifstream in(file.c_str());
  66.   if (!in) return;
  67.  
  68.   while (in.getline(buf,sizeof(buf)))
  69.   {
  70.     if (uStartsWith(buf,"NoImages:")) { if  (buf[9]=='1') flags |= DocViewChoices::NO_IMAGES; }
  71.     else if (uStartsWith(buf,"NoText:"))   { if  (buf[7]=='1') flags |= DocViewChoices::NO_TEXT; }
  72.     else if (uStartsWith(buf,"NoType3Fonts:")) { if  (buf[13]=='1') flags |= DocViewChoices::NO_TYPE3_FONTS; }
  73.     else if (uStartsWith(buf,"NoDrawings:"))   { if  (buf[11]=='1') flags |= DocViewChoices::NO_DRAWINGS; }
  74.     else if (uStartsWith(buf,"HighlightLinks:"))   { if  (buf[15]!='1') 
  75.                                                         flags &= ~DocViewChoices::HIGHLIGHT_LINKS; }
  76.     else if (uStartsWith(buf,"Scale:"))    scale=atoi(buf+6);
  77.     else if (uStartsWith(buf,"Rotation:")) rotation=atoi(buf+9);   
  78.   }
  79. }
  80.  
  81. DefaultChoices& defaultChoices()
  82. {
  83.   static DefaultChoices p;
  84.   return p;
  85. }
  86.  
  87. //*************************************************************************
  88. //*************************************************************************
  89. //*************************************************************************
  90.  
  91. DocViewChoices::DocViewChoices()
  92.  : flags(defaultChoices().flags),
  93.    scale(defaultChoices().scale),
  94.    rotation(defaultChoices().rotation)
  95. {
  96. }
  97.  
  98. //*************************************************************************
  99.  
  100. DocViewChoices::~DocViewChoices() {}
  101.  
  102. //*************************************************************************
  103.  
  104. void DocViewChoices::setScale(int s)
  105. {
  106.   if (s>800) s=800;
  107.   if (s<25) s=25;
  108.   scale=s;
  109. }
  110.  
  111. //*************************************************************************
  112.  
  113. void DocViewChoices::save()
  114. {
  115.   string file=getChoicesFilePath("Setup");
  116.   ofstream out(file.c_str());
  117.   if (!out) return;
  118.  
  119.   defaultChoices().flags=flags;
  120.   defaultChoices().scale=scale;
  121.   defaultChoices().rotation=rotation;
  122.  
  123.   out << "NoImages:"       << (getNoImages()? '1':'0') << endl
  124.       << "NoText:"         << (getNoText()? '1':'0') << endl
  125.       << "NoType3Fonts:"   << (getNoType3Fonts()? '1':'0') << endl
  126.       << "NoDrawings:"     << (getNoDrawings()? '1':'0') << endl
  127.       << "HighlightLinks:" << (getHighlightLinks()? '1':'0') << endl
  128.       << "Scale:"          << scale << endl
  129.       << "Rotation:"       << rotation << endl;
  130. }
  131.